package xml;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.awt.Point;

/**
 * Switches between a java ready {@link java.awt.Point Point} object, and a {@link xml.PointType PointType} object list needed to write to xml.
 * @author mylesc,varunr
 *
 */
public class PointAdapter extends XmlAdapter<PointType, Point> {
	
	/**
	 * Marshals a java Point object into a PointType object which is capable of being saved in xml.
	 * @param p an object to be converted into xml saveable format.
	 * @return pType an object ready to be saved to xml.
	 */
	public PointType marshal(Point p) throws Exception {
		PointType pType = new PointType(p); 

		return pType;
	}

	/**
	 * Unmarshals the PointType form of the Point and creates a new java ready Point.
	 * @param pType an object that contains all data saved for this Point.
	 * @return p an object created from the saved data in an xml file.
	 */
	public Point unmarshal(PointType pType) throws Exception { 
		Point p = new Point();
		p.setLocation(pType.getX(), pType.getY());
		
		return p;
	}
}